/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

package XOrules;

import java.util.*;
import java.lang.*;
import java.math.*;

public class Request {
    public final static String	MSG_USR	 = "USR";
    public final static String	MSG_TYPE = "TYPE";
    public final static String	MSG_BODY = "BODY";

    public String	usr;
    public String	type;
    public String	bodyText;
    public Object	body;
    public Object	answer;
    public String	who;
    public boolean	isAns;

    public Request(TreeMap<String, String> msg) {
	this.usr      = msg.get(MSG_USR);
	this.type     = msg.get(MSG_TYPE);
	this.bodyText = msg.get(MSG_BODY);
	//answer
	this.answer   = null;
	this.who      = null;
	this.isAns    = false;
    }

    public Request Answer(KA who_, Object ... ans_) {
	if (ans_.length == 1){
	    this.answer = ans_[0];
	}

        this.answer = ans_;
	this.who    = who_.name;
	this.isAns  = true;

	return this;
    }

    public String getAnswer() {
        Object answer_;
	if (!this.isAns){
	    answer_ = null;
	}
	else{
	    answer_ = this.answer;
	}
	return null; /*json.dumps(answer);*/
    }
}
